package com.study.algorithm.sort;

import java.util.Arrays;

public class InsertionSort {
    public static void sort(int[] nums) {
        for (int i = 1; i < nums.length; i++) {
            int cur = nums[i];
            int preIndex = i - 1;
            while (preIndex >= 0 && cur < nums[preIndex]) {
                nums[preIndex + 1] = nums[preIndex];
                preIndex -= 1;
            }
            nums[preIndex + 1] = cur;
        }
    }

    public static void main(String[] args) {
        int[] nums = {1, 5, 8, 7, 1, 2, 5, 4, 66, 5, 84, 5, 110, 4, 5, 4};
        sort(nums);
        System.out.println("nums = " + Arrays.toString(nums));
    }
}
